package admin.action.count.createFile;

import java.io.UnsupportedEncodingException;

import teacher.bean.Paper;
import tools.StringDate;
import admin.databaseToExcel.PullPaperToExcel;

public class PaperCreateAction {
	
	private Paper paper;
	private String date2;
	private int direction;
	
	public Paper getPaper() {
		return paper;
	}
	public void setPaper(Paper paper) {
		this.paper = paper;
	}
	public String getDate2() {
		return date2;
	}
	public void setDate2(String date2) {
		this.date2 = date2;
	}

	public int getDirection() {
		return direction;
	}
	public void setDirection(int direction) {
		this.direction = direction;
	}
	
	public String execute()
	{

		if(this.getPaper()!=null)
		{
			
			if(this.getPaper().getName()==null||this.getPaper().getName().equals(""))
				this.getPaper().setName(null);
			else
			{

					try {
						this.getPaper().setName(new String(this.getPaper().getName().getBytes("iso-8859-1"),"utf-8"));
					} catch (UnsupportedEncodingException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
			}
			if(this.getPaper().getMeetName()==null||this.getPaper().getMeetName().equals(""))
				this.getPaper().setMeetName(null);
			else
			{

					try {
						this.getPaper().setMeetName(new String(this.getPaper().getMeetName().getBytes("iso-8859-1"),"utf-8"));
					} catch (UnsupportedEncodingException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
			}
			if(this.getPaper().getPubNumber()==null||this.getPaper().getPubNumber().equals(""))
				this.getPaper().setPubNumber(null);
			else
			{
					try {
						this.getPaper().setPubNumber(new String(this.getPaper().getPubNumber().getBytes("iso-8859-1"),"utf-8"));
					} catch (UnsupportedEncodingException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
			}
			if(this.getPaper().getFauthor()==null||this.getPaper().getFauthor().equals(""))
				this.getPaper().setFauthor(null);
			else
			{

					try {
						this.getPaper().setFauthor(new String(this.getPaper().getFauthor().getBytes("iso-8859-1"),"utf-8"));
					} catch (UnsupportedEncodingException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
			}
			if(this.getPaper().getOauthor()==null||this.getPaper().getOauthor().equals(""))
				this.getPaper().setOauthor(null);
			else
			{

					try {
						this.getPaper().setOauthor(new String(this.getPaper().getOauthor().getBytes("iso-8859-1"),"utf-8"));
					} catch (UnsupportedEncodingException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
			}
			if(this.getPaper().getTauthor()==null||this.getPaper().getTauthor().equals(""))
				this.getPaper().setTauthor(null);
			else
			{

					try {
						this.getPaper().setTauthor(new String(this.getPaper().getTauthor().getBytes("iso-8859-1"),"utf-8"));
					} catch (UnsupportedEncodingException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
			}
			if(this.getPaper().getPbulication()==null||this.getPaper().getPbulication().equals(""))
				this.getPaper().setPbulication(null);
			else
			{

					try {
						this.getPaper().setPbulication(new String(this.getPaper().getPbulication().getBytes("iso-8859-1"),"utf-8"));
					} catch (UnsupportedEncodingException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
			}
			if(this.getPaper().getDate()!=null)
				this.getPaper().setDate(
						StringDate.StringToDate(
								StringDate.DateToString(
										this.getPaper().getDate())));
			
		}
		Paper pap=new Paper();
		if(this.getDate2()!=null)
		pap.setDate(StringDate.StringToDate(this.getDate2()));
		PullPaperToExcel.paperExcel(3,this.getPaper(), pap,this.getDirection());

		return "succ";
	}

}
